import { ResFileConst } from "../../resource/ResFileConst";
import { ModuleType } from "../common/ModuleType";
import { Language } from "../../../../extend/language/Language";
import { RolePlayer } from "../../scene/player/entity/RolePlayer";
import { PlayerEvent } from "../../scene/events/PlayerEvent";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
import { EffectManager } from "../../manager/EffectManager";
import { GuideTipsManager } from "../../manager/GuideTipsManager";
import { Cache } from "../../cache/Cache";
import { ObjCreate } from "../common/ObjCreate";
import { LevelLimitDefin } from "../../../common/defin/LevelLimitDefin";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { Button } from "../../../../fl/controls/Button";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { SoundManager } from "../../../common/sound/SoundManager";
import { SoundTypeConst } from "../../../common/sound/SoundTypeConst";
import { GameManager } from "../../manager/GameManager";
import { GameController } from "../../mvc/GameController";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { IView } from "../../../mvc/interfaces/IView";
import { GodSoulBtn } from "../../../../ResFileConst/GodSoulBtn";
import { GodSoul } from "../../../../ModuleType/GodSoul";
import { MagicWeaponBtn } from "../../../../ResFileConst/MagicWeaponBtn";
import { MagicWeapon } from "../../../../ModuleType/MagicWeapon";
import { WuXing } from "../../../../ResFileConst/WuXing";
import { WuXing } from "../../../../ModuleType/WuXing";
import { FashionBoxHintBtn } from "../../../../ResFileConst/FashionBoxHintBtn";
import { FashionBox } from "../../../../ModuleType/FashionBox";
import { Market } from "../../../../ResFileConst/Market";
import { Market } from "../../../../ModuleType/Market";
import { SmeltButtonLogo } from "../../../../ResFileConst/SmeltButtonLogo";
import { JewelBtn } from "../../../../ResFileConst/JewelBtn";
import { Jewel } from "../../../../ModuleType/Jewel";
import { Built } from "../../../../ResFileConst/Built";
import { Build } from "../../../../ModuleType/Build";
//class NavSprite
    
    export  class NavSprite /* flash.display.Sprite */
    {
        constructor(arg1: Boolean)
        {
            
            this._btnArray = [];
            this._btnMap = new Map<any, any> /* flash.utils.Dictionary */();
            this._namesArray = [];
            this._namesArray.push({"name": GodSoulBtn, "tip":"", "type": GodSoul});
            this._namesArray.push({"name": MagicWeaponBtn, "tip":"", "type": MagicWeapon});
            this._namesArray.push({"name": WuXing, "tip": Language.getStringByParam(51120, "U"), "type": WuXing});
            this._namesArray.push({"name": FashionBoxHintBtn, "tip": Language.getString(71479), "type": FashionBox});
            this._namesArray.push({"name": Market, "tip": Language.getStringByParam(51021, "Y"), "type": Market});
            this._namesArray.push({"name": SmeltButtonLogo, "tip": Language.getString(51022), "type": null});
            this._namesArray.push({"name": JewelBtn, "tip": Language.getStringByParam(51024, "L"), "type": Jewel});
            this._namesArray.push({"name": Built, "tip": Language.getStringByParam(51023, "K"), "type": Build});
            this.init();
            this.initHighlight();
            RolePlayer.instance.addEventListener(PlayerEvent.RoleLevelUpdate, this.onRoleLevelUpdateHandler, false, int.MAX_VALUE);
            return;
        }

        public get btnMap(): Map<any, any> /* flash.utils.Dictionary */
        {
            return this._btnMap;
        }

        public onGuideFirstPurplePetEquipment(): void
        {
            var loc2=null;
            var loc1=this.getChildByName(ResFileConst.JewelBtn) as GLoadedButton;
            if (loc1) 
            {
                EffectManager.glowFilterReg(loc1, null, 1, 10, 0, 20);
                loc2 = GuideTipsManager.getGuideTips(GuideTipsManager.Dir_BR, Language.getString(20336));
                loc2.x = loc1.x + 10;
                loc2.y = loc1.y + 10;
                addChild(loc2);
            }
            return;
        }

        public setButtonVisible(arg1: string, arg2: Boolean): void
        {
            GLoadedButton(this._btnMap[arg1]).visible = arg2;
            this.updateBtnPosition();
            return;
        }

        /* internal  */updateBtnPosition(): void
        {
            var loc2=0;
            var loc1=this._btnArray.length;
            var loc3;
            --loc3;
            var loc4;
            var loc5=(loc4 = this._btnArray[loc3] as GLoadedButton).x;
            while (loc3 >= 0) 
            {
                if ((loc4 = this._btnArray[loc3] as GLoadedButton) && loc4.visible) 
                {
                    loc4.x = loc2 * -46 + loc5;
                    if (loc4.name != ResFileConst.MagicWeaponBtn) 
                    {
                        if (loc4.name != ResFileConst.WuXing) 
                        {
                        };
                    }
                    ++loc2;
                }
                --loc3;
            }
            return;
        }

        /* internal  */init(): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            var loc5=null;
            var loc4=Cache.instance.role.entityInfo.level;
            var loc6=6 - this._namesArray.length;
            var loc7=0;
            while (loc7 < this._namesArray.length) 
            {
                loc1 = this._namesArray[loc7].name as string;
                loc2 = this._namesArray[loc7].tip as string;
                loc5 = this._namesArray[loc7].type as string;
                loc3 = ObjCreate.createGLoadedButton(loc1, (loc6 + loc7) * 46, 0, 44, 54, this);
                loc3.name = loc1;
                loc3.extName = loc5;
                if (loc1 != ResFileConst.MagicWeaponBtn) 
                {
                    if (loc1 != ResFileConst.WuXing) 
                    {
                        if (loc1 != ResFileConst.JewelBtn) 
                        {
                            if (loc1 != ResFileConst.FashionBoxHintBtn) 
                            {
                                if (loc1 != ResFileConst.Market) 
                                {
                                    if (loc1 != ResFileConst.SmeltButtonLogo) 
                                    {
                                        if (loc1 == ResFileConst.GodSoulBtn) 
                                        {
                                            if (loc4 < 75) 
                                            {
                                                loc3.visible = false;
                                            }
                                        }
                                    }
                                    else 
                                    {
                                        loc3.y = 3;
                                    }
                                }
                                else 
                                {
                                    loc3.y = 2;
                                }
                            }
                            else 
                            {
                                loc3.y = 1;
                            }
                        }
                        else 
                        {
                            loc3.y = 1;
                        }
                    }
                    else 
                    {
                        loc3.x = -2 + (loc6 + loc7) * 46;
                        loc3.y = 2;
                        if (loc4 < LevelLimitDefin.WuxingShowLevel) 
                        {
                            loc3.visible = false;
                        }
                    }
                }
                else 
                {
                    loc3.visible = false;
                    loc3.x = loc3.x - 6;
                    loc3.y = 1;
                }
                if (loc2) 
                {
                    loc3.toolTipData = HTMLUtil.addColor(loc2, "#FFFFFF");
                }
                loc3.addEventListener(flash.events.MouseEvent.CLICK, this.onAutoBtnClickHandler);
                this._btnArray.push(loc3);
                this._btnMap[loc1] = loc3;
                ++loc7;
            }
            this.updateBtnPosition();
            return;
        }

        /* internal  */initHighlight(): void
        {
            var loc2=null;
            var loc1=0;
            while (loc1 < this._btnArray.length) 
            {
                loc2 = this._btnArray[loc1] as Button;
                loc2.addEventListener(flash.events.MouseEvent.MOUSE_OVER, this.onBtnMouseOver);
                loc2.addEventListener(flash.events.MouseEvent.MOUSE_OUT, this.onBtnMouseOut);
                ++loc1;
            }
            return;
        }

        /* internal  */onBtnMouseOver(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.target as Button;
            loc1.filters = [FilterConst.uiBtnFilter];
            return;
        }

        /* internal  */onBtnMouseOut(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.target as Button;
            loc1.filters = [];
            return;
        }

        /* internal  */onAutoBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            SoundManager.instance.soundPlay(SoundTypeConst.UIclick);
            var loc1=arg1.target as Button;
            var loc2=loc1.name;
            var loc3=loc2;
            switch (loc3) 
            {
                case ResFileConst.WuXing:
                {
                    GameManager.instance.popupWindow(ModuleType.WuXing);
                    break;
                }
                case ResFileConst.Market:
                {
                    this.popupView(GameController.market.view);
                    break;
                }
                case ResFileConst.SmeltButtonLogo:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.SmeltSmeltButtonClick));
                    break;
                }
                case ResFileConst.Built:
                {
                    this.popupView(GameController.equipment.view);
                    break;
                }
                case ResFileConst.JewelBtn:
                {
                    this.popupView(GameController.jewel.view);
                    if (Cache.instance.guide.guideFirstPurplePetEquipmentStep == 1) 
                    {
                        GuideTipsManager.hideGuideTips();
                        EffectManager.glowFilterUnReg(loc1);
                    }
                    break;
                }
                case ResFileConst.MagicWeaponBtn:
                {
                    if (Cache.instance.magicWeapon.isCanModuleIconShow(true)) 
                    {
                        if (GameController.magicWeapon.view.isHide) 
                        {
                            this.popupView(GameController.magicWeapon.view);
                        }
                        else 
                        {
                            GameController.magicWeapon.view.hide();
                        }
                    }
                    break;
                }
                case ResFileConst.GodSoulBtn:
                {
                    this.popupView(GameController.godSoul.view);
                    break;
                }
                case ResFileConst.FashionBoxHintBtn:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.FashionBoxModuleShow));
                    break;
                }
            }
            return;
        }

        /* internal  */onRoleLevelUpdateHandler(arg1: Object): void
        {
            var loc2=null;
            var loc3=null;
            var loc1=Cache.instance.role.entityInfo.level;
            if (this._btnArray && this._btnArray.length > 0) 
            {
                loc2 = this._btnMap[ResFileConst.WuXing];
                loc3 = this._btnMap[ResFileConst.GodSoulBtn];
                loc2.visible = loc1 >= LevelLimitDefin.WuxingShowLevel;
                loc3.visible = loc1 >= 75;
            }
            this.updateBtnPosition();
            return;
        }

        /* internal  */popupView(arg1: IView): void
        {
            if (arg1.isHide) 
            {
                arg1.show();
            }
            else 
            {
                arg1.hide();
            }
            return;
        }

        public updateShortcutKey(arg1: Array<any>): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc6=0;
            var loc5=0;
            while (loc5 < arg1.length) 
            {
                loc1 = arg1[loc5];
                if (typeof loc1.key === "string") 
                {
                    loc6 = 0;
                    while (loc6 < this._btnArray.length) 
                    {
                        if ((loc3 = this._btnArray[loc6] as GLoadedButton).extName && loc3.extName == loc1.key) 
                        {
                            if (loc1.keyData) 
                            {
                                if ((loc4 = loc1.keyData.shortcutsName) == "") 
                                {
                                    loc3.toolTipData = HTMLUtil.addColor(loc1.keyMapName, "#FFFFFF");
                                }
                                else 
                                {
                                    loc3.toolTipData = HTMLUtil.addColor(loc1.keyMapName, "#FFFFFF") + HTMLUtil.addColor("(" + loc1.keyData.shortcutsName + ")", "#00FF00");
                                }
                            }
                            else 
                            {
                                loc3.toolTipData = null;
                            }
                        }
                        ++loc6;
                    }
                }
                ++loc5;
            }
            return;
        }

        /* internal */ /* var */_btnArray: Array<any>;

        /* internal */ /* var */_namesArray: Array<any>;

        /* internal */ /* var */_btnMap: Map<any, any> /* flash.utils.Dictionary */;
    }
